package com.gaoch.simweather.ui.place

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import com.gaoch.simweather.logic.Repository
import com.gaoch.simweather.logic.model.PlaceResponse


class PlaceViewModel:ViewModel() {
    private val searchLiveData=MutableLiveData<String>()
    val placeList=ArrayList<PlaceResponse.Location>()

    val placeLiveData=Transformations.switchMap(searchLiveData){
        Repository.searchPlaces(it)
    }

    fun searchPlaces(query:String){
        searchLiveData.value=query
    }

    fun savePlace(place:PlaceResponse.Location)=Repository.savePlace(place)

    fun getSavedPlace()=Repository.getSavePlace()

    fun isPlaceSaved()=Repository.isPlaceSaved()
}